<?php

class Core_Backend_Component_Subject_View_Content_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('subject/content/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'create') . "')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $model = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('content_form')
                ->addHiddenField('id', 'content[id]');
        $form->addTextboxField($this->__('share.label.name'), 'name', 'content[name]', TRUE)
                ->addValidateRule('required');
        $form->addComboTreeField($this->__('subject.label.category'), 'category_id', "content[category_id]", TRUE)
                ->bindData($this->getCategories()->toArray(), 0, array('valueKey' => 'id', 'textKey' => 'name', 'parentKey' => 'parent_id', 'childKey' => 'id'));
        $form->addSelectField($this->__('subject.label.player'), 'account_ids', "content[account_ids][]", TRUE)
                ->setMultiple(TRUE)
                ->setSize(20)
                ->bindData($this->getAccounts()->toArray(), 'full_name', 'id');
        if(!empty($model)){
            $form->bindData($model->toArray());
        }
        parent::buildForm($form);
    }

}